<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		$(function(){
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=ck_id]").attr("checked","checked");
				}else{
					$("input[name=ck_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
			
	
		});
		
		function bianYe(pageIndex){
			document.form1.action="AdminServlet.do?pageIndex=" + pageIndex;
			document.form1.submit();
		}
		
		function zhuanYe(){
			var pageIndex=document.getElementById("pageIndex").value;
			bianYe(pageIndex);
		}
		
		function suo(item,id,pageIndex){
			var msg;
			var flag;
			if(item=="true"){
				msg="确定要锁定吗";
			}
			if(item=="false"){
				msg="确定要解锁吗";
			}
			if(confirm(msg)){
				$(".suo").attr("href","AdminServlet.do?flag=adminsuo&id="+id+"&pageIndex="+pageIndex+"&item="+item);
			}else{
				return false;
			}
		}
		function shanchuone(id){
			var adminid = '${admin_session.id}';
			if(adminid==id){
				alert("不可以删除自己");
				return false;
			}else{
				return confirm("确认要删除吗");
			}
		}
		function deletemore(pageIndex){
			var list=document.getElementsByName("ck_id");
			var id = '${admin_session.id}';
			var flag=false;
			for(var i=0;i<list.length;i++){
				if(list[i].checked==true){
					if(list[i].value==id){
						alert("不可以删除自己");
						return false;
					}
					flag=true;
				}
			}
			if(flag==true){
				if(confirm("确定要删除吗")){
					var href=$()
					document.form1.action="AdminServlet.do?flag=moredelete&pageIndex=" + pageIndex;
					document.form1.submit();
					return false;/* 让form表单提交进行多个删除   超链接不提交  如果超链接也提交就回提交两次 */
				}else{
					return false;
				}
				
			}else{
				alert("至少选中一个才可以删除");
				return false;
			}
		}
		</script>
		
		<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
		<style type="text/css">
			#adminName{
				width:200px;/* 来设定用户账号那一栏固定长度 */
			}
		</style>
		
  </head>
  
  <body>
    <div class ="div_title">
		<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
		<div class="div_titleoper">
			<input type="checkbox" id="top_ch_checkall"/> 全选 <a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> <a href="AdminServlet.do?flag=moredelete" onclick="return deletemore('${pageInfo.pageIndex}')"><img src="images/del.gif"/>删除</a> </div>
		</div>
				 
		 <form action="AdminServlet.do"  name="form1" method="post">
		<input type="hidden" name="flag" value="weihu">
		 <table class="main_table" >
		       <tr>
		 				<th><input type="checkbox" id="ch_checkall" /></th>	<th id="adminName">账号</th> 	<th>状态</th>	<th>备注</th>  <th>最后更新日期</th> 	<th>操作</th>
		 		</tr>
		 		<c:forEach var="admin" items="${ adminList}">
		 			<tr>
		 				<td><input type="checkbox" name="ck_id" value="${ admin.id}" /> </td>
		 				<td id="adminName" >${admin.adminName }</td>
		 				<td>
		 					<c:if test="${admin.state==2 }">已锁定</c:if>
		 				</td>
		 				<td ><a title="${admin.note }" class="note_a">${admin.note }</a></td>
		 				<td><fmt:formatDate value="${admin.editDate }" pattern="yyyy年MM月dd日"/></td>
		 				<td>
			 				<c:if test="${admin.state=='1' }">
				 				<a class="suo" href="AdminServlet.do" onclick="return suo('true','${admin.id}','${pageInfo.pageIndex}')">锁定</a> |  
				 				<a href="AdminServlet.do?flag=adminGoUpdate&id=${admin.id}" onclick="return confirm('确认要修改吗')">修改</a> |  	
				 			   
			 			    </c:if>
			 			    <c:if test="${admin.state=='2' }">
			 			    	<a class="suo" href="AdminServlet.do" onclick="return suo('false','${admin.id}','${pageInfo.pageIndex}')">解锁</a> |  
			 			    </c:if>
			 			     <a  href="AdminServlet.do?flag=admindelete&id=${admin.id}&pageIndex=${pageInfo.pageIndex}" onclick="return shanchuone('${admin.id}')">删除</a> 
			 			</td>
		 			</tr>
		 		</c:forEach>
		</table>
		</form>
		
		<div class="div_page" >
			  <div class="div_page_left">    共有 <label>${pageInfo.rowCount }</label> 条记录，当前第 <label>${pageInfo.pageIndex }</label> 页，共 <label>${pageInfo.pageCount }</label> 页	</div>		
			  <div class="div_page_right" > 	 
			  		<c:choose>
				  		<c:when test="${pageInfo.hasPre }">
				  			<input type="submit" value="首页" onclick="bianYe(1)"/>
				  			<input type="submit" value="上一页" onclick="bianYe(${pageInfo.pageIndex-1 })"/>
				  			
				  		</c:when>
				  		<c:otherwise>
				  			首页  上一页
				  		</c:otherwise>
				  	</c:choose>
				  	<c:choose>
				  		<c:when test="${pageInfo.hasNext }">
				  			<input type="submit" value="下一页" onclick="bianYe(${pageInfo.pageIndex+1 })"/>
				  			<input type="submit" value="尾页" onclick="bianYe(${pageInfo.pageCount })"/>
				  		</c:when>
				  		<c:otherwise>
				  			下一页 尾页
				  		</c:otherwise>
				  	</c:choose>
					<input type="submit" value="转到" onclick="zhuanYe()">
			  		<input type="text" name="pageIndex" id="pageIndex" name="pageIndex" value="${pageInfo.pageIndex }" /> 页
			  	
			   </div>
		</div>
		<script >
			var t="${adminManage}";
			if(t!=""){
				alert(t);
			}
		</script>
  </body>
</html>